from fnmatch import fnmatch, fnmatchcase

# 用Shell通配符匹配字符串
def demo_1():
    # fnmatch函数使用底层操作系统的大小写敏感规则（不同的系统是不一样的）来匹配模式
    # fnmatch函数匹配能力介于简单的字符串方法和强大的正则之间
    print(fnmatch('foo.txt', '*.txt'))
    print(fnmatch('foo.txt', '?*.txt'))
    print(fnmatch('Dat45.csv', 'Dat[0-9]*'))
    names = ['Dat1.csv', 'Dat2.csv', 'config.ini', 'foo.py']
    check_result = [name for name in names if fnmatch(name, 'Dat*.csv')]
    print(check_result)

    # windows使用规则大小写相同，Mac不同
    print(fnmatch('foo.txt', '*.TXT'))

def demo_2():
    addresses = [
        '4523 N KEPLER ST',
        '6643 N KEPLE AVE',
        '1285 S KEPL ST',
        '2351 E KEP',
        '0932 W K ST'
    ]
    result_1 = [addr for addr in addresses if fnmatchcase(addr, '* ST')]
    print(result_1)
    result_2 = [addr for addr in addresses if fnmatchcase(addr, '45[0-9][0-9] *KEP*')]
    print(result_2)

if __name__ == '__main__':
    # demo_1()
    demo_2()